package com.hema.auction.adapter;

import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hema.auction.R;
import com.hema.auction.bean.GoodsInfo;
import com.hema.auction.utils.GlideUtils;
import com.hema.auction.utils.Utils;
import com.hema.auction.utils.manager.SPManager;

import java.util.List;

/**
 * author by john
 */

public class MyAuctionAdapter extends BaseQuickAdapter<GoodsInfo, BaseViewHolder> {

    private String status;

    public MyAuctionAdapter(List<GoodsInfo> data) {
        super(R.layout.layout_my_auction_item, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, GoodsInfo item) {
        helper.setText(R.id.tv_date, Utils.timedate(item.getFinalTime()));
        helper.addOnClickListener(R.id.tv_action1);
        helper.addOnClickListener(R.id.tv_action2);

        ImageView view = helper.getView(R.id.iv_img);
        GlideUtils.load(mContext, item.getImg(), view);
        helper.setText(R.id.tv_market_price, Utils.priceUnitFormat(mContext, item.getPrice()));

        if (item.getStatus() == 6) {
            helper.setText(R.id.tv_status, "进行中");
            helper.setText(R.id.tv_action1, "继续竞拍");
            helper.setVisible(R.id.tv_action1, true);
            helper.setText(R.id.tv_action1, "查看详情");
            helper.setVisible(R.id.tv_action2, true);

            helper.setText(R.id.tv_auction_price_title, mContext.getString(R.string.auction_price_tip));
            helper.setText(R.id.tv_auction_price, Utils.priceUnitFormat(mContext, item.getFinalPrice()));
            helper.setText(R.id.tv_dealer_price_title, mContext.getString(R.string.i_bid_tip));
            helper.setText(R.id.tv_dealer_price, item.getOrderCount() + "次");
            helper.setVisible(R.id.tv_date,false);
        } else if (SPManager.getInstance(mContext).getUserId().equals(item.getUid())) {
            helper.setVisible(R.id.tv_date,true);
            //我拍中的
            switch (item.getStatus()) {
                //订单状态  订单状态  0->未付款，1->已付款(待发货)，2->已发货(待签收)，3->已收货(待晒单)，4->已过期，5->已取消,6未竞拍结束
                case 0:
                    helper.setText(R.id.tv_status, "待付款");

                    helper.setText(R.id.tv_action1, "立即付款");
                    helper.setVisible(R.id.tv_action1, true);
                    helper.setVisible(R.id.tv_action2, false);

                    helper.setText(R.id.tv_auction_price_title, mContext.getString(R.string.auction_price_tip));
                    helper.setText(R.id.tv_auction_price, Utils.priceUnitFormat(mContext, String.valueOf(item.getFinalPrice())));
                    helper.setText(R.id.tv_dealer_price_title, mContext.getString(R.string.dealer));
                    helper.setText(R.id.tv_dealer_price, item.getOwnerName());
                    break;
                case 1:
                    helper.setText(R.id.tv_status, "已付款");

                    helper.setVisible(R.id.tv_action1, false);
                    helper.setText(R.id.tv_action2, "查看详情");
                    helper.setVisible(R.id.tv_action2, true);

                    helper.setText(R.id.tv_auction_price_title, mContext.getString(R.string.auction_price_tip));
                    helper.setText(R.id.tv_auction_price, Utils.priceUnitFormat(mContext, item.getFinalPrice()));
                    helper.setText(R.id.tv_dealer_price_title, mContext.getString(R.string.final_price_tip));
                    helper.setText(R.id.tv_dealer_price, Utils.priceUnitFormat(mContext, item.getFinalPrice()));
                    break;
                case 2:
                    helper.setText(R.id.tv_status, "已发货");

                    helper.setVisible(R.id.tv_action1, false);
                    helper.setText(R.id.tv_action2, "查看详情");
                    helper.setVisible(R.id.tv_action2, true);

                    helper.setText(R.id.tv_auction_price_title, mContext.getString(R.string.auction_price_tip));
                    helper.setText(R.id.tv_auction_price, Utils.priceUnitFormat(mContext, item.getFinalPrice()));
                    helper.setText(R.id.tv_dealer_price_title, mContext.getString(R.string.final_price_tip));
                    helper.setText(R.id.tv_dealer_price, Utils.priceUnitFormat(mContext, item.getFinalPrice()));
                    break;
                case 3:
                    helper.setText(R.id.tv_status, "已签收");

                    helper.setText(R.id.tv_action1, "我要晒单");
                    helper.setVisible(R.id.tv_action1, true);
                    helper.setText(R.id.tv_action2, "查看详情");
                    helper.setVisible(R.id.tv_action2, true);

                    helper.setText(R.id.tv_auction_price_title, mContext.getString(R.string.auction_price_tip));
                    helper.setText(R.id.tv_auction_price, Utils.priceUnitFormat(mContext, item.getFinalPrice()));
                    helper.setText(R.id.tv_dealer_price_title, "成交人：");
                    helper.setText(R.id.tv_dealer_price, item.getOwnerName());
                    break;
                case 4:
                    helper.setText(R.id.tv_status, "已过期");
                    helper.setVisible(R.id.tv_action1, false);
                    helper.setText(R.id.tv_action2, "查看详情");
                    helper.setVisible(R.id.tv_action2, true);

                    helper.setText(R.id.tv_auction_price_title, mContext.getString(R.string.auction_price_tip));
                    helper.setText(R.id.tv_auction_price, Utils.priceUnitFormat(mContext, item.getFinalPrice()));
                    helper.setText(R.id.tv_dealer_price_title, mContext.getString(R.string.final_price_tip));
                    helper.setText(R.id.tv_dealer_price, Utils.priceUnitFormat(mContext, item.getFinalPrice()));
                    break;
                case 5:
                    helper.setText(R.id.tv_status, "已完成");
                    helper.setVisible(R.id.tv_action1, false);
                    helper.setText(R.id.tv_action2, "查看详情");
                    helper.setVisible(R.id.tv_action2, true);

                    helper.setText(R.id.tv_auction_price_title, mContext.getString(R.string.auction_price_tip));
                    helper.setText(R.id.tv_auction_price, Utils.priceUnitFormat(mContext, item.getFinalPrice()));
                    helper.setText(R.id.tv_dealer_price_title, mContext.getString(R.string.final_price_tip));
                    helper.setText(R.id.tv_dealer_price, Utils.priceUnitFormat(mContext, item.getFinalPrice()));
                    break;
                case 6:
                    if (item.getUid().equals("0"))
                        helper.setText(R.id.tv_status, "进行中");
                    helper.setText(R.id.tv_action1, "继续竞拍");
                    helper.setVisible(R.id.tv_action1, true);
                    helper.setText(R.id.tv_action2, "查看详情");
                    helper.setVisible(R.id.tv_action2, true);

                    helper.setText(R.id.tv_auction_price_title, mContext.getString(R.string.auction_price_tip));
                    helper.setText(R.id.tv_auction_price, Utils.priceUnitFormat(mContext, item.getFinalPrice()));
                    helper.setText(R.id.tv_dealer_price_title, mContext.getString(R.string.i_bid_tip));
                    helper.setText(R.id.tv_dealer_price, item.getOrderCount() + "次");
                    break;

            }
        } else {
            //未拍中
            helper.setText(R.id.tv_status, "未拍中");
            helper.setText(R.id.tv_action1, "差价购买");
            helper.setVisible(R.id.tv_action1, true);
            helper.setVisible(R.id.tv_action2, false);

            helper.setText(R.id.tv_auction_price_title, mContext.getString(R.string.auction_price_tip));
            helper.setText(R.id.tv_auction_price, Utils.priceUnitFormat(mContext, item.getFinalPrice()));
            helper.setText(R.id.tv_dealer_price_title, mContext.getString(R.string.dealer));
            helper.setText(R.id.tv_dealer_price, item.getOwnerName());
            helper.setVisible(R.id.tv_date,true);
        }
        status = ((TextView) helper.getView(R.id.tv_status)).getText().toString();

    }

    public String getStatus() {
        return status;
    }

    public String getAction() {
        return status;
    }

}
